
local ScreenScale = ScreenScale
local PANEL = {}

function PANEL:Init()

	self.allorgs = vgui.Create( "DPanel", self )
	self:AddSheet( "Organization Listings", self.allorgs, "gui/silkicons/group", "A Listing of all organizations" )
	
	self.orglist = vgui.Create( "DListView", self.allorgs )
	self.orglist:SetPos( 5, 5 )
	self.orglist:SetSize( ScreenScale( 220 ), ScreenScale( 50 ) )
	self.namecol = self.orglist:AddColumn( "Name" )
	self.countcol = self.orglist:AddColumn( "Count" )
	self.ldrcol = self.orglist:AddColumn( "Leader" )
	
	self.btnClose = vgui.Create( "DSysButton", self )
	self.btnClose:SetType( "close" )
	self.btnClose.DoClick = function ( button ) self:Remove() end
	self.btnClose:SetDrawBackground( true )

end

function PANEL:AddSheet( label, panel, icon, tooltip )
	
	panel.Paint = function()
		draw.RoundedBox( 6, 0, 0, self:GetWide(), self:GetTall(), Color( 200, 200, 200, 255 ) )
	end
	DPropertySheet.AddSheet( self, label, panel, icon, false, false, tooltip )
	
end	

function PANEL:Paint()
	
	DPropertySheet.Paint( self )

end

function PANEL:PerformLayout()

	DPropertySheet.PerformLayout( self )
	self:SetSize( ScreenScale( 400 ), ScreenScale( 100 ) )
	self:Center()
	
	self.btnClose:SetSize( ScreenScale( 8 ), ScreenScale( 8 ) )
	self.btnClose:SetPos( self:GetWide() - ScreenScale( 8 ), 0 )
	
	self.namecol:SetWide( ScreenScale( 100 ) )
	self.countcol:SetWide( ScreenScale( 20 ) )
	self.ldrcol:SetWide( ScreenScale( 100 ) )

end

function PANEL:Open()

	self:SetVisible( true )
	self:SetAlpha( 255 )
	self:MakePopup()

end

vgui.Register( "OrgMenu", PANEL, "DPropertySheet" )
// End of definition

local function openOrgMenu()

	if ( g_Omenu ) then
	
		g_Omenu:Remove()
		g_Omenu = nil
	
	end

	g_Omenu = vgui.Create( "OrgMenu" )
	g_Omenu:Open()

end

// Development command to reload the opane (usually just use gamemode_reload)
concommand.Add( "organization", function() openOrgMenu() end )

openOrgMenu()

